import request from "@/utils/request";

/**
 * 获取参建单位
 */
export function getProjectCorps() {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/getProjectCorps";
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/getProjectCorps";
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/getProjectCorps";
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/getProjectCorps";
      break;
    //   case "SysUser":
    //     url = "/api/v1/sysuser/checkindetail/page_person_month";
    //     break;
  }

  return request({
    url: url,
    method: "get",
  });
}

//获取总包分包，除去监理
export function getProjectCorpsNoJL() {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/getProjectCorpsNoJL";
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/getProjectCorpsNoJL";
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/getProjectCorpsNoJL";
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/getProjectCorpsNoJL";
      break;
    //   case "SysUser":
    //     url = "/api/v1/sysuser/checkindetail/page_person_month";
    //     break;
  }

  return request({
    url: url,
    method: "get",
  });
}

//获取项目班组列表
export function getProjectGroups(corpId?: number, keywords?: string) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/getProjectGroups";
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/getProjectGroups";
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/getProjectGroups";
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/getProjectGroups";
      break;
    //   case "Commander":
    //     url = "/api/v1/commander/checkindetail/page_person_month";
    //     break;
    //   case "SysUser":
    //     url = "/api/v1/sysuser/checkindetail/page_person_month";
    //     break;
  }

  return request({
    url: url,
    method: "get",
    params: { corpId: corpId, keywords: keywords },
  });
}

export function getProjectGroupsByGroupId(groupId?: number) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/getProjectGroupsByGroupId";
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/getProjectGroupsByGroupId";
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/getProjectGroupsByGroupId";
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/getProjectGroupsByGroupId";
      break;
    //   case "Constructor":
    //     url = "/api/v1/constructor/checkindetail/page_person_month";
    //     break;
    //   case "Commander":
    //     url = "/api/v1/commander/checkindetail/page_person_month";
    //     break;
    //   case "SysUser":
    //     url = "/api/v1/sysuser/checkindetail/page_person_month";
    //     break;
  }

  return request({
    url: url,
    method: "get",
    params: { groupId: groupId },
  });
}

export function getProjectGroupMembers(groupId?: number) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/getProjectGroupMembers";
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/getProjectGroupMembers";
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/getProjectGroupMembers";
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/getProjectGroupMembers";
      break;
    //   case "Constructor":
    //     url = "/api/v1/constructor/checkindetail/page_person_month";
    //     break;
    //   case "Commander":
    //     url = "/api/v1/commander/checkindetail/page_person_month";
    //     break;
    //   case "SysUser":
    //     url = "/api/v1/sysuser/checkindetail/page_person_month";
    //     break;
  }

  return request({
    url: url,
    method: "get",
    params: { groupId: groupId },
  });
}

export function deleteGroups(groupIds?: any) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/" + groupIds;
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/" + groupIds;
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/" + groupIds;
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/" + groupIds;
      break;
    //   case "Commander":
    //     url = "/api/v1/commander/checkindetail/page_person_month";
    //     break;
    //   case "SysUser":
    //     url = "/api/v1/sysuser/checkindetail/page_person_month";
    //     break;
  }

  return request({
    url: url,
    method: "delete",
  });
}

export function getGroupForm(groupId?: number) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/" + groupId + "/form";
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/" + groupId + "/form";
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/" + groupId + "/form";
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/" + groupId + "/form";
      break;
    //   case "Commander":
    //     url = "/api/v1/commander/checkindetail/page_person_month";
    //     break;
    //   case "SysUser":
    //     url = "/api/v1/sysuser/checkindetail/page_person_month";
    //     break;
  }

  return request({
    url: url,
    method: "get",
  });
}

/**
 * 添加
 *
 * @param data
 */
export function addGroup(data: projectGroupForm) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/create";
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/create";
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/create";
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/create";
      break;
    //   case "Commander":
    //     url = "/api/v1/commander/checkindetail/page_person_month";
    //     break;
    //   case "SysUser":
    //     url = "/api/v1/sysuser/checkindetail/page_person_month";
    //     break;
  }

  return request({
    url: url,
    method: "post",
    data: data,
  });
}

/**
 * 更新
 *
 * @param id
 * @param data
 */
export function updateGroup(id: number, data: projectGroupForm) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/" + id;
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/" + id;
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/" + id;
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/" + id;
      break;
    //   case "Commander":
    //     url = "/api/v1/commander/checkindetail/page_person_month";
    //     break;
    //   case "SysUser":
    //     url = "/api/v1/sysuser/checkindetail/page_person_month";
    //     break;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}

/**
 * 一键进场
 *
 */
export function inGroups(ids: string) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/enterArena/" + ids;
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/enterArena/" + ids;
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/enterArena/" + ids;
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/enterArena/" + ids;
      break;
    //   case "Commander":
    //     url = "/api/v1/commander/checkindetail/page_person_month";
    //     break;
    //   case "SysUser":
    //     url = "/api/v1/sysuser/checkindetail/page_person_month";
    //     break;
  }
  return request({
    url: url,
    method: "put",
  });
}

/**
 * 一键离场
 *
 */
export function outGroups(ids: string) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/appearStage/" + ids;
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/appearStage/" + ids;
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/appearStage/" + ids;
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/appearStage/" + ids;
      break;
    //   case "Commander":
    //     url = "/api/v1/commander/checkindetail/page_person_month";
    //     break;
    //   case "SysUser":
    //     url = "/api/v1/sysuser/checkindetail/page_person_month";
    //     break;
  }
  return request({
    url: url,
    method: "put",
  });
}

/**
 * 班组下拉
 *
 */
export function pullDownGroups(corpId: number) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/pulldown/" + corpId;
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/pulldown/" + corpId;
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/pulldown/" + corpId;
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/pulldown/" + corpId;
      break;
    //   case "Commander":
    //     url = "/api/v1/commander/checkindetail/page_person_month";
    //     break;
    //   case "SysUser":
    //     url = "/api/v1/sysuser/checkindetail/page_person_month";
    //     break;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 更换人员所在班组
 *
 * @param data
 */
export function updatePersonMember(data: UpdatePersonMemberformData) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/editPersonGroup";
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/editPersonGroup";
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/editPersonGroup";
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/editPersonGroup";
      break;
    //   case "Commander":
    //     url = "/api/v1/commander/checkindetail/page_person_month";
    //     break;
    //   case "SysUser":
    //     url = "/api/v1/sysuser/checkindetail/page_person_month";
    //     break;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}

/**
 * 单个人员进场
 *
 * @param data
 */
export function inGroupMember(id: number) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/inGroupMember/" + id;
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/inGroupMember/" + id;
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/inGroupMember/" + id;
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/inGroupMember/" + id;
      break;
    //   case "Commander":
    //     url = "/api/v1/commander/checkindetail/page_person_month";
    //     break;
    //   case "SysUser":
    //     url = "/api/v1/sysuser/checkindetail/page_person_month";
    //     break;
  }
  return request({
    url: url,
    method: "put",
  });
}

/**
 * 单个人员离场
 *
 * @param data
 */
export function outGroupMember(id: number) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/outGroupMember/" + id;
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/outGroupMember/" + id;
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/outGroupMember/" + id;
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/outGroupMember/" + id;
      break;
    //   case "Commander":
    //     url = "/api/v1/commander/checkindetail/page_person_month";
    //     break;
    //   case "SysUser":
    //     url = "/api/v1/sysuser/checkindetail/page_person_month";
    //     break;
  }
  return request({
    url: url,
    method: "put",
  });
}

/**
 * 导出Excel
 */
export function downloadGroups() {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/export";
      break;
    case "Corp":
      url = "/api/v1/Corp/projectgroup/export";
      break;
    case "Constructor":
      url = "/api/v1/Constructor/projectgroup/export";
      break;
    case "Commander":
      url = "/api/v1/Commander/projectgroup/export";
      break;
    //   case "Commander":
    //     url = "/api/v1/commander/checkindetail/page_person_month";
    //     break;
    //   case "SysUser":
    //     url = "/api/v1/sysuser/checkindetail/page_person_month";
    //     break;
  }
  return request({
    url,
    method: "get",
    responseType: "arraybuffer",
  });
}

export function OnSiteVerification(data: any) {
  let url = "/api/v1/manager/projectgroup/onSiteVerification";
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/onSiteVerification";
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/onSiteVerification";
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/onSiteVerification";
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/onSiteVerification";
      break;
    //   case "Commander":
    //     url = "/api/v1/commander/checkindetail/page_person_month";
    //     break;
    //   case "SysUser":
    //     url = "/api/v1/sysuser/checkindetail/page_person_month";
    //     break;
  }
  return request({
    url,
    method: "post",
    data: data,
  });
}
